package com.lxj.controller;

import com.lxj.domain.Sign;
import com.lxj.service.SignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ResponseBody
@Controller
@RequestMapping("/sign")
public class SignController {
    @Autowired
    private SignService signService;

    @PostMapping("/selectAll")
    public Map<String, Object> selectAll(Sign sign) {
        Map<String, Object> map = new HashMap<>();
        List<Sign> list = signService.selectAll(sign);
        int number = signService.getCount();
        map.put("list", list);
        map.put("number", number);
        return map;
    }

    @GetMapping("/signInDelete")
    public int signInDelete(Integer[] id) {
        return signService.signInDelete(id);
    }

    @PostMapping("/findById")
    public Sign findById(Integer id) {
        return signService.findById(id);
    }

    @PostMapping("/edit")
    public int edit(Sign sign) {
        return signService.edit(sign);
    }

    @PostMapping("/add")
    public int add(Sign sign) {
        int result = 0;
        int a = signService.judge(sign);
        if (a == 0) {
            result = signService.add(sign);
        } else {
            result = 2;
        }
        return result;
    }

    @PostMapping("/selectOutAll")
    public Map<String, Object> selectOutAll(Sign sign) {
        Map<String, Object> map = new HashMap<>();
        List<Sign> list = signService.selectOutAll(sign);
        int number = signService.getOutCount();
        map.put("list", list);
        map.put("number", number);
        return map;
    }

    @GetMapping("/signOutDelete")
    public int signOutDelete(Integer[] id) {
        return signService.signOutDelete(id);
    }

    @PostMapping("/findOutById")
    public Sign findOutById(Integer id) {
        return signService.findOutById(id);
    }

    @PostMapping("/outEdit")
    public int outEdit(Sign sign) {
        return signService.outEdit(sign);
    }

    @PostMapping("/outAdd")
    public int outAdd(Sign sign) {
        int result = 0;
        int a = signService.outJudge(sign);
        if (a == 0) {
            result = signService.outAdd(sign);
        } else {
            result = 2;
        }
        return result;
    }

    @PostMapping("/findAll")
    public Map<String, Object> findAll(Sign sign) {
        Map<String, Object> map = new HashMap<>();
        List<Sign> list = signService.findAll(sign);
        int number = signService.getNumber(sign);
        map.put("list", list);
        map.put("number", number);
        return map;
    }
    @PostMapping("signDelete")
    public int signDelete(Sign sign){
        return signService.signDelete(sign);
    }
}
